﻿#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <numeric>
#include <vector>

// 二分数字组合

using namespace std;

int solution(int n, int A, int B, vector<int> array_a) {
    int sum_total = accumulate(array_a.begin(), array_a.end(), 0);
    int sum_mod = sum_total % 10;

    vector<vector<int>> dp(n + 1, vector<int>(10, 0));
    dp[0][0] = 1;

    for (int i = 0; i < n; ++i) {
        int num = array_a[i] % 10;
        for (int j = 0; j < 10; ++j) {
            int next = (j + num) % 10;
            dp[i + 1][next] += dp[i][j];
            dp[i + 1][j] += dp[i][j];
        }
    }

    vector<int> count(10, 0);
    for (int j = 0; j < 10; ++j) {
        count[j] = dp[n][j];
        if (j == 0) count[j]--;
        if (j == sum_mod) count[j]--;
        if (count[j] < 0) count[j] = 0;
    }

    int sum_count = 0;
    for (int j = 0; j < 10; ++j) {
        int complement = (sum_mod - j + 10) % 10;
        if ((j == A && complement == B) || (j == B && complement == A)) {
            sum_count += count[j];
        }
    }

    int case1 = (A != B) ? (sum_count / 2) : sum_count;
    int case2 = (sum_mod == A || sum_mod == B) ? 1 : 0;

    return case1 + case2;
}

int main() {
    std::vector<int> array1 = { 1, 1, 1 };
    std::vector<int> array2 = { 1, 1, 1 };
    std::vector<int> array3 = { 1, 1 };

    std::cout << (solution(3, 1, 2, array1) == 3) << std::endl;
    std::cout << (solution(3, 3, 5, array2) == 1) << std::endl;
    std::cout << (solution(2, 1, 1, array3) == 2) << std::endl;

    return 0;
}